package com.thti.mecool.client.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.ListView;

import com.thti.mecool.client.adapter.UserCenterFirstListAdapter;
import com.thti.mecool.client.base.BaseActivity;
import com.thti.mecool.client.base.Cache;
import com.thti.mecool.client.model.biz.MessagesBizImpl;
import com.thti.mecool.client.widget.Toolbar;

public class UserCenterActivity extends BaseActivity{
	private ListView listView;
	UserCenterFirstListAdapter adapter;
	MessagesBizImpl messagesBizImpl;
	private int msgNum;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.noTitle();
		setContentView(R.layout.mecool_usercenter);
		Cache.add(this);		
		initToolbar();
		init();
		service();
	}
	
	private void init(){
		listView=(ListView)findViewById(R.id.mecool_usercenter_listview);
		String[] userFunction=new String[]{"修改密码","消息"};
		messagesBizImpl=new MessagesBizImpl(this);
		msgNum=messagesBizImpl.findall().size();
		adapter=new UserCenterFirstListAdapter(this, userFunction,msgNum);
	}
	
	private void service(){
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(clickListener);
	}
	
	OnItemClickListener clickListener=new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			Intent intent = new Intent();
			switch (Integer.parseInt(arg1.getTag().toString())) {
			case 0:
				intent.setClass(UserCenterActivity.this,UpdatePasswdActivity.class);
				startActivity(intent);
				break;
			case 1:
				intent.setClass(UserCenterActivity.this, UserCenterMsgListActivity.class);
				startActivity(intent);
				break;
			}
		}
	};
	
	
	public void initToolbar(){
		Toolbar toolbar=new Toolbar(this);
		Toolbar.hideRightButton();
		toolbar.setToolbarCentreText("个人中心");
		Toolbar.left_btn.setOnClickListener(leftbuttonListener);
		Toolbar.left_btn.setImageResource(R.drawable.mecool_go_back);
	}
	
	private OnClickListener leftbuttonListener=new ImageButton.OnClickListener(){

		@Override
		public void onClick(View v) {
			finish();
	}};
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		msgNum=messagesBizImpl.findall().size();
		adapter.notifyDataSetChanged();
	}
	
	
	
				
}
